import { reqGetTradeInfoData } from "@/api";

const state = {
  tradeInfo: {}, //用来存储订单交易的信息
};
const actions = {
  // 1.获取订单交易信息
  async getTradeInfoData({ commit }) {
    const result = await reqGetTradeInfoData();
    if (result.code === 200) {
      console.log("112");
      commit("SAVE_TRADE_INFO_DATA", result.data);
    }
  },
};
const mutations = {
  // 1.将获取的订单交易信息保存
  SAVE_TRADE_INFO_DATA(state, tradeInfo) {
    state.tradeInfo = tradeInfo;
  },
};
const getters = {
  // 1. 订单编号
  tradeNo(state) {
    return state.tradeInfo.tradeNo;
  },
  // 2. 商品数量
  totalNum(state) {
    return state.tradeInfo.totalNum;
  },
  // 3. 商品详细列表
  detailArrayList(state) {
    return state.tradeInfo.detailArrayList;
  },
  // 4. 总金额
  totalAmount(state) {
    return state.tradeInfo.totalAmount;
  },
};

export default {
  namespaced: true,
  state,
  actions,
  mutations,
  getters,
};
